﻿// Attitude Indicator - 姿态指示仪

#include "AttitudeIndicator.h"



void screwAtI(float CENTER_X, float CENTER_Y, float DIAL_RADIUS)//螺丝
{
    // 使用float保证计算精度（根据需求可改为double）
    const float DIAL_RADIUS_F = (float)DIAL_RADIUS;
    const float CENTER_X_F = (float)CENTER_X;
    const float CENTER_Y_F = (float)CENTER_Y;

    // 参数化定义（精确到小数点后6位）
    const float SCREW_OFFSET = DIAL_RADIUS_F * 0.055555556f; // 1/18
    const float ELLIPSE_OFFSET_X = -DIAL_RADIUS_F * 0.111111111f; // -1/9
    const float ELLIPSE_OFFSET_Y = -DIAL_RADIUS_F * 0.166666667f; // -1/6
    const float ELLIPSE_SIZE = DIAL_RADIUS_F * 0.277777778f;  // 5/18
    const float RECT_OFFSET_X = DIAL_RADIUS_F * 0.222222222f;  // 2/9
    const float RECT_OFFSET_Y = DIAL_RADIUS_F * 0.333333333f;  // 1/3
    const float RECT_WIDTH = DIAL_RADIUS_F * 0.555555556f;   // 5/9
    const float RECT_HEIGHT = DIAL_RADIUS_F * 0.611111111f;  // 11/18
    const float CROSS_OFFSET1 = DIAL_RADIUS_F * 0.055555556f;  // 1/18
    const float CROSS_OFFSET2 = DIAL_RADIUS_F * 0.027777778f;  // 1/36
    const float LINE_WIDTH = DIAL_RADIUS_F * 0.016666667f;  // 1/60

    ege_enable_aa(TRUE);

    // 绘制函数（使用浮点坐标）
    auto draw_screw = [&](float cx, float cy) {
        // 精确到小数点后6位的渐变参数
        ege_setpattern_ellipsegradient(
            ege_point{ roundf(cx), roundf(cy) }, // 最终转整数
            EGEACOLOR(0xFF, BLACK),
            roundf(cx + ELLIPSE_OFFSET_X),
            roundf(cy + ELLIPSE_OFFSET_Y),
            roundf(ELLIPSE_SIZE),
            roundf(ELLIPSE_SIZE),
            EGEACOLOR(0, WHITE)
        );
        ege_fillrect(
            roundf(cx - RECT_OFFSET_X),
            roundf(cy - RECT_OFFSET_Y),
            roundf(RECT_WIDTH),
            roundf(RECT_HEIGHT)
        );

        // 灰色渐变层（精确尺寸调整）
        const float adjusted_size = ELLIPSE_SIZE - DIAL_RADIUS_F * 0.055555556f; // 替代原-10
        ege_setpattern_ellipsegradient(
            ege_point{
                    roundf(cx - SCREW_OFFSET * 0.5f),
                    roundf(cy - SCREW_OFFSET * 0.5f)
            },
            EGEACOLOR(0xFF, EGERGB(170, 170, 170)),
            roundf(cx + ELLIPSE_OFFSET_X),
            roundf(cy + ELLIPSE_OFFSET_Y),
            roundf(adjusted_size),
            roundf(adjusted_size),
            EGEACOLOR(0xFF, EGERGB(20, 20, 20))
        );
        ege_fillrect(
            roundf(cx - RECT_OFFSET_X),
            roundf(cy - RECT_OFFSET_Y),
            roundf(RECT_WIDTH),
            roundf(RECT_HEIGHT)
        );

        // 十字线（亚像素级精度）
        setcolor(EGERGB(30, 30, 30));
        setlinewidth(roundf(LINE_WIDTH));

        const float cross_y = cy - CROSS_OFFSET2 * 2.0f;
        ege_line(
            roundf(cx - CROSS_OFFSET1), roundf(cross_y),
            roundf(cx + CROSS_OFFSET1), roundf(cross_y)
        );

        const float cross_x = cx;
        const float cross_y_start = cy + CROSS_OFFSET2 / 4;
        const float cross_y_end = cy - CROSS_OFFSET2 * 4.0f;
        ege_line(
            roundf(cross_x), roundf(cross_y_start),
            roundf(cross_x), roundf(cross_y_end)
        );
        };

    // 计算四个螺丝中心坐标（浮点运算）
    const float screw_radius = DIAL_RADIUS_F - SCREW_OFFSET;

    // 左上
    draw_screw(
        CENTER_X_F - screw_radius,
        CENTER_Y_F - DIAL_RADIUS_F
    );

    // 右上
    draw_screw(
        CENTER_X_F + screw_radius,
        CENTER_Y_F - DIAL_RADIUS_F
    );

    // 右下
    draw_screw(
        CENTER_X_F + screw_radius,
        CENTER_Y_F + DIAL_RADIUS_F
    );

    // 左下（新增）
    draw_screw(
        CENTER_X_F - screw_radius,
        CENTER_Y_F + DIAL_RADIUS_F
    );
}
// pitch 为俯仰角  roll 为滚转角 单位都是弧度
void drawAT(int x0, int y0, float r, float pitch, float roll) {
    // 设置窗口标题
//    setcaption("Attitude Indicator");
    // 初始化图形窗口
//    initgraph(width, height, INIT_RENDERMANUAL);
//    setbkcolor(EGEARGB(255, 69, 69, 68));
    ege_enable_aa(true);
    float angle = roll;
    int width, height;
    width = height = 2 * r;
    PIMAGE img = newimage(width, height);
    int delayx = x0 - r;
    int delayy = y0 - r;

    setrendermode(RENDER_MANUAL);

    // 计算缩放因子和中心点
    float originalSize = 720.0f; // 原始窗口大小
    float scale_x = width / originalSize;  // X 方向缩放因子
    float scale_y = height / originalSize; // Y 方向缩放因子
    float new_xCenter = width / 2.0f;
    float new_yCenter = height / 2.0f;
    //screwAtI(x0, y0 + 10 * scale_x, r - 95 * scale_x);

    // 原始参数
    float original_radius = 300.0f; // 最大实际的圆为315.0f(窗口在720下的)
    // 辅助函数：获取缩放后的坐标
    auto get_scaled_x = [&](float x) { return new_xCenter + x * scale_x; };
    auto get_scaled_y = [&](float y) { return new_yCenter + y * scale_y; };
    auto get_scaled_size_x = [&](float size) { return size * scale_x; };
    auto get_scaled_size_y = [&](float size) { return size * scale_y; };
    auto get_scaled_linewidth = [&](float width) { return (int)(width * (scale_x + scale_y) / 2); }; // 平均缩放线宽

    float new_inRadius = get_scaled_size_x((original_radius - 30) * 2) / 2;
    //    float angle = 0;
    float y = 0;

    //    for(; is_run(); delay_fps(90), angle += PI / 150) {
    //        cleardevice();
    setbkcolor(EGERGBA(0, 0, 0, 0), img);
    float angle1 = angle * 180 / PI;
    //y = sin(pitch) * 90 * scale_x;// 220
    if (pitch >= -25 && pitch <= 25)
    {
        y = (pitch / 25.0) * 90 * scale_x;
    }
    else if (pitch > 25)
    {
        y = 90 * scale_x;
    }
    else
    {
        y = -90 * scale_x;
    }
    // 绘制外层到内层圆（按比例缩放）不用动

//        setlinestyle(NULL_LINE);
    setfillcolor(EGEARGB(255, 4, 4, 4));
    //        setfillcolor(EGEARGB(255, 168, 255, 128));
    ege_fillellipse(get_scaled_x(-original_radius - 15) + delayx, get_scaled_y(-original_radius - 15) + delayy,
        get_scaled_size_x((original_radius + 15) * 2), get_scaled_size_y((original_radius + 15) * 2));
    //        setfillcolor(EGERGB(0, 0, 0));
    //        ege_point p1 = { new_xCenter + delayx + get_scaled_size_x((original_radius + 15) * 2) / 2.0 * cos(105 / 180.0 * M_PI) - 10 * scale_x
    //                         ,new_xCenter + delayx + get_scaled_size_x((original_radius + 15) * 2) / 2.0 * sin(105 / 180.0 * M_PI) - 10 * scale_y};
    //        ege_setpattern_ellipsegradient(p1, EGEARGB(255, 160, 160, 160), get_scaled_x(-original_radius - 15) + delayx, get_scaled_y(-original_radius - 15) + delayy,
    //                                   get_scaled_size_x((original_radius + 15) * 2), get_scaled_size_y((original_radius + 15) * 2), EGEARGB(255, 4, 4, 4));
    //    setfillcolor(EGERGB(0, 0, 0));//黑色,不透
    //    {
    //        setcolor(BLACK);//描边颜色
    //        setlinewidth(20);//线条粗细
    //        ege_circle(new_xCenter + delayx, new_yCenter + delayy, (original_radius ) * scale_x);//描边
    //
    //        setfillcolor(EGEARGB(255, 31, 28, 25));
    //        ege_point p1 = { 1174,224 };
    //        ege_setpattern_ellipsegradient(p1, EGEARGB(255, 160, 160, 160), get_scaled_x(-original_radius - 15) + delayx, get_scaled_y(-original_radius - 15) + delayy,
    //                       get_scaled_size_x((original_radius + 15) * 2), get_scaled_size_y((original_radius + 15) * 2), EGEARGB(255, 4, 4, 4));
    //    }//最外圈
    //
    setfillcolor(EGEARGB(255, 31, 28, 25));
    ege_fillellipse(get_scaled_x(-original_radius - 5) + delayx, get_scaled_y(-original_radius - 5) + delayy,
        get_scaled_size_x((original_radius + 5) * 2), get_scaled_size_y((original_radius + 5) * 2));


    setfillcolor(EGEARGB(255, 5, 5, 5));
    ege_fillellipse(get_scaled_x(-original_radius + 15) + delayx, get_scaled_y(-original_radius + 15) + delayy,
        get_scaled_size_x((original_radius - 15) * 2), get_scaled_size_y((original_radius - 15) * 2));


    setfillcolor(EGEARGB(255, 37, 33, 31));
    ege_fillellipse(get_scaled_x(-original_radius + 20) + delayx, get_scaled_y(-original_radius + 20) + delayy,
        get_scaled_size_x((original_radius - 20) * 2), get_scaled_size_y((original_radius - 20) * 2));


    setfillcolor(EGEARGB(255, 10, 10, 10));
    ege_fillellipse(get_scaled_x(-original_radius + 25) + delayx, get_scaled_y(-original_radius + 25) + delayy,
        get_scaled_size_x((original_radius - 25) * 2), get_scaled_size_y((original_radius - 25) * 2));

    // 绘制上下半部分（天空和地面）

    ege_enable_aa(true);
    setfillcolor(EGEARGB(255, 95, 156, 184)); // 天空（蓝色）
    ege_fillpie(get_scaled_x(-original_radius + 30) + delayx, get_scaled_y(-original_radius + 30) + delayy,
        get_scaled_size_x((original_radius - 30) * 2), get_scaled_size_y((original_radius - 30) * 2), 180 + angle1,
        180);


    ege_enable_aa(true);
    setfillcolor(EGEARGB(255, 84, 54, 22)); // 地面（棕色）
    ege_fillpie(get_scaled_x(-original_radius + 30) + delayx, get_scaled_y(-original_radius + 30) + delayy,
        get_scaled_size_x((original_radius - 30) * 2), get_scaled_size_y((original_radius - 30) * 2), 0 + angle1,
        180);

    // 绘制倾斜椭圆（按比例调整）绘制到img中去

    ege_enable_aa(true, img);
    setfillcolor(EGEARGB(255, 107, 173, 205), img); // 天空部分
    ege_fillpie(get_scaled_x(-230), get_scaled_y(-130),
        get_scaled_size_x(460), get_scaled_size_y(260), 180, 360, img);


    setfillcolor(EGEARGB(255, 107, 69, 28), img); // 地面部分
    ege_fillpie(get_scaled_x(-230), get_scaled_y(-130),
        get_scaled_size_x(460), get_scaled_size_y(260), 0, 180, img);

    // 绘制水平分界线和刻度
    ege_enable_aa(true, img);
    setlinestyle(SLASH_FILL, EGEARGB(255, 255, 255, 255), get_scaled_linewidth(6), img);
    setlinewidth(get_scaled_linewidth(6), img); // 缩放线宽
    setlinecolor(EGEARGB(255, 255, 255, 255), img);
    ege_line(get_scaled_x(-230), new_yCenter, get_scaled_x(230), new_yCenter, img);

    setlinewidth(get_scaled_linewidth(3), img);
    setlinecolor(EGEARGB(255, 0, 0, 0), img);
    ege_line(get_scaled_x(-12), get_scaled_y(-18), get_scaled_x(12), get_scaled_y(-18), img);
    ege_line(get_scaled_x(-30), get_scaled_y(-36), get_scaled_x(30), get_scaled_y(-36), img);
    ege_line(get_scaled_x(-12), get_scaled_y(-54), get_scaled_x(12), get_scaled_y(-54), img);
    ege_line(get_scaled_x(-60), get_scaled_y(-72), get_scaled_x(60), get_scaled_y(-72), img);
    ege_line(get_scaled_x(-12), get_scaled_y(-90), get_scaled_x(12), get_scaled_y(-90), img);


    setlinewidth(get_scaled_linewidth(3), img);
    setlinecolor(EGEARGB(255, 255, 255, 255), img);
    ege_line(get_scaled_x(-9), get_scaled_y(18), get_scaled_x(9), get_scaled_y(18), img);
    ege_line(get_scaled_x(-12), get_scaled_y(54), get_scaled_x(12), get_scaled_y(54), img);
    ege_line(get_scaled_x(-12), get_scaled_y(90), get_scaled_x(12), get_scaled_y(90), img);

    // 绘制文本
    settextjustify(CENTER_TEXT, CENTER_TEXT, img);
    setcolor(BLACK, img);
    setfont((int)(25 * scale_y), 0, "Arial Narrow", img);
    setbkmode(TRANSPARENT, img);
    ege_outtextxy(get_scaled_x(-45), get_scaled_y(-36 - 10), "10", img);
    ege_outtextxy(get_scaled_x(45), get_scaled_y(-36 - 10), "10", img);
    ege_outtextxy(get_scaled_x(-75), get_scaled_y(-72 - 10), "20", img);
    ege_outtextxy(get_scaled_x(75), get_scaled_y(-72 - 10), "20", img);

    // 绘制其他线条和标记
    setlinestyle(SLASH_FILL, EGEARGB(255, 255, 255, 255), get_scaled_linewidth(4), img);
    setlinewidth(get_scaled_linewidth(4), img);
    setlinecolor(EGEARGB(255, 255, 255, 255), img);
    ege_line(new_xCenter, new_yCenter, get_scaled_x(207.76), get_scaled_y(55.67), img);
    ege_line(new_xCenter, new_yCenter, get_scaled_x(-207.76), get_scaled_y(55.67), img);
    ege_line(new_xCenter, new_yCenter, get_scaled_x(105.4), get_scaled_y(116.5), img);
    ege_line(new_xCenter, new_yCenter, get_scaled_x(-105.4), get_scaled_y(116.5), img);
    ege_line(get_scaled_x(-135), get_scaled_y(36), get_scaled_x(135), get_scaled_y(36), img);
    ege_line(get_scaled_x(-192), get_scaled_y(72), get_scaled_x(192), get_scaled_y(72), img);

    // 绘制下部标记和文本
    settextjustify(CENTER_TEXT, CENTER_TEXT, img);
    setcolor(WHITE, img);
    setbkmode(TRANSPARENT, img);
    setfillcolor(EGEARGB(255, 107, 69, 28), img);
    ege_fillellipse(get_scaled_x(-45), get_scaled_y(36 - 15), get_scaled_size_x(30), get_scaled_size_y(30), img);
    ege_outtextxy(get_scaled_x(-30), get_scaled_y(36 - 10), "10", img);
    ege_fillellipse(get_scaled_x(20), get_scaled_y(36 - 15), get_scaled_size_x(30), get_scaled_size_y(30), img);
    ege_outtextxy(get_scaled_x(35), get_scaled_y(36 - 10), "10", img);
    ege_fillellipse(get_scaled_x(-77), get_scaled_y(72 - 15), get_scaled_size_x(30), get_scaled_size_y(30), img);
    ege_fillellipse(get_scaled_x(50), get_scaled_y(72 - 15), get_scaled_size_x(30), get_scaled_size_y(30), img);
    ege_outtextxy(get_scaled_x(-62), get_scaled_y(72 - 10), "20", img);
    ege_outtextxy(get_scaled_x(65), get_scaled_y(72 - 10), "20", img);


    ege_transform_matrix m;
    //保存旧的坐标变换矩阵
    ege_get_transform(&m);
    ege_transform_translate((getwidth(img)) / 2.0 + delayx, (getwidth(img)) / 2.0 + delayy); //平移到屏幕中心
    ege_transform_rotate(angle1); // 顺时针旋转角度
    ege_transform_translate((-getwidth(img)) / 2 - delayx, (-getheight(img)) / 2 - y - delayy); // 平移图片img中心
    ege_drawimage(img, 0 + delayx, 0 + delayy);
    //恢复原有坐标变换
    ege_set_transform(&m);

    // 绘制外圆环
    // 实现旋转
    ege_enable_aa(TRUE);
    setlinestyle(SLASH_FILL, EGEARGB(255, 110, 163, 226));
    setlinewidth(get_scaled_linewidth(60));
    setlinecolor(EGEARGB(255, 107, 173, 205));
    ege_arc(get_scaled_x(-original_radius + 60) + delayx, get_scaled_y(-original_radius + 60) + delayy,
        get_scaled_size_x((original_radius - 60) * 2), get_scaled_size_y((original_radius - 60) * 2), 180 + angle1, 180);


    ege_enable_aa(TRUE);
    setlinestyle(SLASH_FILL, EGEARGB(255, 102, 65, 26));
    setlinewidth(get_scaled_linewidth(60));
    setlinecolor(EGEARGB(255, 107, 69, 28));
    ege_arc(get_scaled_x(-original_radius + 60) + delayx, get_scaled_y(-original_radius + 60) + delayy,
        get_scaled_size_x((original_radius - 60) * 2), get_scaled_size_y((original_radius - 60) * 2), 0 + angle1, 180);
    // 绘制圆环上的刻度
    setlinecolor(EGEARGB(255, 255, 255, 255));
    setlinewidth(get_scaled_linewidth(5));
    ege_enable_aa(TRUE);
    for (double i = 0; i < 360; i += 10) {
        double inangle = i * M_PI / 180 + angle;
        if (i > 69 + 180 && i < 111 + 180 && i != 180 + 90) {
            double x1 = new_xCenter + (original_radius - 90) * cos(inangle) * scale_x + delayx;
            double y1 = new_yCenter + (original_radius - 90) * sin(inangle) * scale_y + delayy;
            double x2 = new_xCenter + (original_radius - 50) * cos(inangle) * scale_x + delayx;
            double y2 = new_yCenter + (original_radius - 50) * sin(inangle) * scale_y + delayy;
            ege_line(x1, y1, x2, y2);
        }
    }


    for (double i = 0; i <= 360; i += 30) {
        double inangle = i * M_PI / 180 + angle;
        if (i > 179 && i != 180 + 90) {
            setlinewidth(get_scaled_linewidth(12));
            double x1 = new_xCenter + (original_radius - 90) * cos(inangle) * scale_x + delayx;
            double y1 = new_yCenter + (original_radius - 90) * sin(inangle) * scale_y + delayy;
            double x2 = new_xCenter + (original_radius - 42) * cos(inangle) * scale_x + delayx;
            double y2 = new_yCenter + (original_radius - 42) * sin(inangle) * scale_y + delayy;
            ege_line(x1, y1, x2, y2);
        }
        if (i == 180 + 90) {
            setlinewidth(get_scaled_linewidth(12));
            double x1 = new_xCenter + (original_radius - 90) * cos(inangle) * scale_x + delayx;
            double y1 = new_yCenter + (original_radius - 90) * sin(inangle) * scale_y + delayy;
            double x2 = new_xCenter + (original_radius - 70) * cos(inangle) * scale_x + delayx;
            double y2 = new_yCenter + (original_radius - 70) * sin(inangle) * scale_y + delayy;
            ege_line(x1, y1, x2, y2);

            float r3 = get_scaled_linewidth(13);
            setlinewidth(get_scaled_linewidth(12));
            x2 = new_xCenter + (original_radius - 54) * cos(inangle) * scale_x + delayx;
            y2 = new_yCenter + (original_radius - 54) * sin(inangle) * scale_y + delayy;
            // 圆环的中心是 (x2, y2)，半径是 r3
            ege_arc(x2 - r3, y2 - r3, r3 * 2, r3 * 2, 0 + angle1, 360);
        }
    }
    // 结束外圆环的旋转

// 绘制橙色双对标
    ege_point pointsLeftOrange[] = {
            new_xCenter - 2 * scale_x + delayx, new_yCenter - 270 * scale_y + delayy,
            new_xCenter - 2 * scale_x + delayx, new_yCenter - 210 * scale_y + delayy,
            new_xCenter - (2 + 9) * scale_x + delayx, new_yCenter - 210 * scale_y + delayy,
            new_xCenter - (2 + 25) * scale_x + delayx, new_yCenter - 270 * scale_y + delayy,
    };
    ege_point pointsRightOrange[] = {
            new_xCenter + 2 * scale_x + delayx, new_yCenter - 270 * scale_y + delayy,
            new_xCenter + 2 * scale_x + delayx, new_yCenter - 210 * scale_y + delayy,
            new_xCenter + (2 + 9) * scale_x + delayx, new_yCenter - 210 * scale_y + delayy,
            new_xCenter + (2 + 25) * scale_x + delayx, new_yCenter - 270 * scale_y + delayy,
    };
    setfillcolor(EGEARGB(255, 247, 89, 45));
    ege_fillpoly(4, pointsLeftOrange);
    ege_fillpoly(4, pointsRightOrange);

    // 准心下的三角形
    ege_point pointsTriangle[] = {
            new_xCenter + delayx, new_yCenter - 5 * scale_y + delayy,
            new_xCenter - 10 * scale_x + delayx, new_yCenter + 60 * scale_y + delayy,
            new_xCenter + 10 * scale_x + delayx, new_yCenter + 60 * scale_y + delayy,
    };
    setfillcolor(EGEARGB(255, 64, 41, 16));
    ege_fillpoly(3, pointsTriangle);

    // 绘制准心
    setlinestyle(NULL_LINE);
    setfillcolor(EGEARGB(255, 247, 89, 45));
    ege_fillellipse(new_xCenter - 5 * scale_x + delayx, new_yCenter - 5 * scale_y + delayy,
        10 * scale_x, 10 * scale_y);

    ege_point points1[4] = {
            {get_scaled_x(-120) + delayx,    new_yCenter - 5 * scale_y + delayy},
            {get_scaled_x(-120) + delayx,    new_yCenter + 5 * scale_y + delayy},
            {get_scaled_x(-40 + 4) + delayx, new_yCenter + 5 * scale_y + delayy},
            {get_scaled_x(-40 + 4) + delayx, new_yCenter - 5 * scale_y + delayy}
    };

    setfillcolor(EGEARGB(255, 247, 89, 45));
    ege_fillpoly(4, points1);

    ege_point points2[4] = {
            {get_scaled_x(120) + delayx,    new_yCenter - 5 * scale_y + delayy},
            {get_scaled_x(120) + delayx,    new_yCenter + 5 * scale_y + delayy},
            {get_scaled_x(40 - 4) + delayx, new_yCenter + 5 * scale_y + delayy},
            {get_scaled_x(40 - 4) + delayx, new_yCenter - 5 * scale_y + delayy}
    };

    setfillcolor(EGEARGB(255, 247, 89, 45));
    ege_fillpoly(4, points2);

    // 绘制底
    setlinestyle(SOLID_LINE);
    ege_enable_aa(true);
    float startAngle = 30;
    float endAngle = 150;
    setlinewidth(get_scaled_linewidth(4));
    setlinecolor(EGERGB(7, 6, 5));
    ege_arc(get_scaled_x(-original_radius + 30) + delayx, get_scaled_y(-original_radius + 30) + delayy,
        get_scaled_size_x((original_radius - 30) * 2), get_scaled_size_y((original_radius - 30) * 2),
        startAngle, endAngle - startAngle);
    setlinecolor(EGERGB(7, 6, 5));
    //线条粗细
    setlinewidth(get_scaled_linewidth(4));
    ege_line(
        new_xCenter - new_inRadius * sin((endAngle - startAngle) * M_PI / 360.0f) - get_scaled_linewidth(3) + delayx,
        new_yCenter + new_inRadius * cos((endAngle - startAngle) * M_PI / 360.0f) + get_scaled_linewidth(6) + delayy,
        new_xCenter + new_inRadius * sin((endAngle - startAngle) * M_PI / 360.0f) + get_scaled_linewidth(4) + delayx,
        new_yCenter + new_inRadius * cos((endAngle - startAngle) * M_PI / 360.0f) + get_scaled_linewidth(3) + delayy
    );
    setfillcolor(EGERGB(34, 30, 28));

    int numArcPoints = 400;
    ege_point pointsdown[400 + 2]; // 使用 POINT 数组，每个元素包含 x 和 y

    // 计算圆弧上的点
    for (int i = 0; i < numArcPoints; ++i) {
        float angle = startAngle + (endAngle - startAngle) * i / numArcPoints;
        pointsdown[i].x = new_xCenter + new_inRadius * cos(angle * PI / 180.0f) + delayx; // 赋值给 POINT 的 x 成员
        pointsdown[i].y = new_yCenter + new_inRadius * sin(angle * PI / 180.0f) + delayy; // 赋值给 POINT 的 y 成员
    }

    // 计算直线的两个端点
    float lineStartX = new_xCenter - new_inRadius * sin((endAngle - startAngle) * PI / 360.0f) + delayx;
    float lineStartY = new_yCenter + new_inRadius * cos((endAngle - startAngle) * PI / 360.0f) + delayy;
    float lineEndX = new_xCenter + new_inRadius * sin((endAngle - startAngle) * PI / 360.0f) + delayx;
    float lineEndY = lineStartY;

    // 添加直线端点到 POINT 数组
    pointsdown[numArcPoints] = { lineStartX, lineStartY }; // 直接初始化 POINT 结构体
    pointsdown[numArcPoints + 1] = { lineEndX, lineEndY };

    setfillcolor(EGERGB(34, 30, 28));
    ege_fillpoly(numArcPoints + 2, pointsdown); // 传递 POINT 数组

    setlinecolor(EGERGB(3, 3, 3));
    //线条粗细
    setlinewidth(get_scaled_linewidth(4));
    ege_line(
        new_xCenter - new_inRadius * sin((endAngle - startAngle) * M_PI / 360.0f) - get_scaled_linewidth(3) + delayx,
        new_yCenter + new_inRadius * cos((endAngle - startAngle) * M_PI / 360.0f) + get_scaled_linewidth(4) + delayy,
        new_xCenter + new_inRadius * sin((endAngle - startAngle) * M_PI / 360.0f) + get_scaled_linewidth(3) + delayx,
        new_yCenter + new_inRadius * cos((endAngle - startAngle) * M_PI / 360.0f) + get_scaled_linewidth(4) + delayy
    );
    // 绘制底部按钮
    int i;
    for (i = 0; i < 35; i++) {
        setfillcolor(EGEARGB(255, 6, 6, 5));
        ege_fillcircle(new_xCenter + delayx, new_yCenter + 202.5 * scale_y + i * scale_y + delayy, 47.5 * scale_x);
    }
    setfillcolor(EGEARGB(255, 32, 29, 27));
    ege_fillcircle(new_xCenter + delayx, new_yCenter + 202.5 * scale_y + i * scale_y + delayy, 47.5 * scale_x);

    setlinewidth(get_scaled_linewidth(2));
    setlinecolor(EGERGB(7, 6, 5));
    ege_arc(get_scaled_x(0 - (47.5 - 10)) + delayx, get_scaled_y(202.5 + i - (47.5 - 10)) + delayy,
        get_scaled_size_x((47.5 - 10) * 2), get_scaled_size_y((47.5 - 10) * 2), 0, 360);

    // 绘制底部梯形
    ege_point pointsTrapezoid[] = {
            new_xCenter + 23 * scale_x + delayx, new_yCenter + (137 - 80) * scale_y + delayy,
            new_xCenter + 57 * scale_x + delayx, new_yCenter + 137 * scale_y + delayy,
            new_xCenter - 57 * scale_x + delayx, new_yCenter + 137 * scale_y + delayy,
            new_xCenter - 23 * scale_x + delayx, new_yCenter + (137 - 80) * scale_y + delayy,
    };
    setlinecolor(EGERGB(7, 6, 5));
    setlinewidth(get_scaled_linewidth(5));
    ege_line(
        new_xCenter + 57 * scale_x + delayx,
        new_yCenter + 137 * scale_y + delayy,
        new_xCenter + 23 * scale_x + delayx,
        new_yCenter + (137 - 80) * scale_y + delayy
    );
    ege_line(
        new_xCenter + 25 * scale_x + delayx,
        new_yCenter + (137 - 80) * scale_y + delayy,
        new_xCenter - 25 * scale_x + delayx,
        new_yCenter + (137 - 80) * scale_y + delayy
    );
    ege_line(
        new_xCenter - 57 * scale_x + delayx,
        new_yCenter + 137 * scale_y + delayy,
        new_xCenter - 23 * scale_x + delayx,
        new_yCenter + (137 - 80) * scale_y + delayy
    );

    setfillcolor(EGEARGB(255, 34, 29, 27));
    ege_fillpoly(4, pointsTrapezoid);

    // 底部棕色半圆环

    setlinewidth(get_scaled_linewidth(10));
    setlinecolor(EGEARGB(255, 64, 41, 16));
    ege_arc(get_scaled_x(0 - 40) + delayx, get_scaled_y(5 - 40) + delayy,
        get_scaled_size_x(40 * 2), get_scaled_size_y(40 * 2), 0, 180);

    setbkmode(TRANSPARENT);
    setfont((int)(15 * scale_y), 0, "CAAC_Num&Let_NSS-Small");
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    setcolor(WHITE);
    ege_outtextxy(get_scaled_x(0) + delayx, get_scaled_y(120 - 10) + delayy, "ATTITUDE");
    delimage(img);
    //    }
    //    closegraph();
}